<template>
	<view v-if="showCoupon">
		<!-- <MmvTitle :title="'优惠券'" :moreLink="couponLink"></MmvTitle>
		<view class="wrap">
			<u-scroll-list :indicator="false">
				<view class="coupon-item" v-for="(item, index) in couponList" :key="index">
					<homeCoupon 
					:businessId="item.businessId" 
					:couponName="item.couponName" 
					:couponContent="item.preferentialInfo" 
					:storeCount="item.applicableUnit" 
					:isReceive="item.isReceive" 
					@getCoupon="getCoupon"></homeCoupon></view>
			</u-scroll-list>
		</view> -->
		
		
		<drag-button
			:isDock="true"
			:existTabBar="true"
			@aaa="couponclick" >
				<image :src="home_coupon_bg | imageUrl" mode="scaleToFill" style="width: 150upx;height: 180upx;"></image>
		</drag-button>
		
		
		<!-- <login-mask></login-mask> -->
	</view>
</template>

<script>
// import MmvTitle from '@/components/layout/mmv-home-title.vue';
// import homeCoupon from '@/components/coupon/home-coupon.vue';
// import loginMask from '@/components/layout/login-mask.vue';
import dragButton from '@/components/drag-button/drag-button.vue';
import {apiHomeCoupon,receiveCoupons,getIfHaveCoupon} from '../../../common/api.js';
import GLOBAL_CONFIG from '@/common/config';

export default {
	name: 'coupon',
	components: {
		// MmvTitle,
		// homeCoupon,
		// loginMask,
		dragButton,
	},
	data() {
		return {
			// couponList: [],
			couponLink: '../../pages/coupon/home-moreCoupon',
			home_coupon_bg:'uni_rental/优惠券@2x.png',
		}
	},
	computed: {
	    storeInfo() {
	        return this.$store.state.app.storeInfo;
	    },
		tenantId() {
		    return this.$store.state.user.tenantId;
		},
		deptId() {
		    return this.$store.state.user.deptId;
		},
		showCoupon() {
		    return this.$store.state.home.showDragCoupon;
		},
	},	
	mounted() {
		// uni.$on('refreshCouponData', ()=> {
		// 	this.getData();
		// });
		this.getData();
		// uni.$on('store_selected', res=>{
			
		// })
	},
	destroyed() {
		clearTimeout(this.timer);
	},
	filters: {
		imageUrl(url) {
			return GLOBAL_CONFIG.baseImageUrl + url;
		},
	},
	methods: {
		getData() {
			getIfHaveCoupon({
				tenantId:this.tenantId,
				applicableUnitNo:this.deptId,
			}).then(res=>{
				this.$store.commit('home/setShowDragCoupon', res);
			})
		},
		
		// getCoupon(data){
		// 	if(uni.$u.test.isEmpty(this.$store.state.user.userInfo)){
		// 		this.$store.dispatch('user/MmvLogin').then(data=>{
		// 			 this.getData();
		// 		}).catch(err=>{
		// 			 uni.showToast({ title: '授权失败', icon: 'error' });
		// 		})
		// 		return
		// 	}
		// 	receiveCoupons({
		// 		memberNo : this.$store.state.user.userInfo.customerId,
		// 		businessId : data.businessId,
		// 	}).then(res => {
		// 		this.getData()
		// 	})
		// },
		
		couponclick(){
			uni.navigateTo({
				url:'/pages/coupon/coupon_square',
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.wrap {
	padding: $page_padding;
}
.coupon-item {
	background: 0;
	& + & {
		margin-left: 30upx;
	}
}
</style>
